package org.openfdtd.core3d;

import java.util.ArrayList;
import javax.media.j3d.BranchGroup;

/**
 *
 * @author Dórian C. Langbeck
 */
public class EditableObject3D extends Object3D {

    public static EditableObject3D buildEditable(Object3D obj) {
        return null;
    }

    protected boolean editable = false;
    protected SelectionMode selectionMode;
    protected ArrayList<Surface> selecteds;

    public EditableObject3D(Surface[] faces) {
        super(faces);
        setCapability(BranchGroup.ALLOW_DETACH); //Permite que este objeto seja excluido
        
        selecteds = new ArrayList<Surface>();
        selectionMode = SelectionMode.SINGLE_SELECTION;
    }

    void surfaceSelected(Surface face, boolean m) {
        if (m && selectionMode == SelectionMode.MULTI_SELECTION)
            if (selecteds.contains(face)) {
                selecteds.remove(face);
                face.setAppearance(style.getActiveAppearance());
            } else {
                selecteds.add(face);
                face.setAppearance(style.getSelectedAppearance());
            }
        else {
            //TODO: Criar um metodo para aplicar o estilo apenas aos selecionados
            selecteds.clear();
            changeAppearance(style.getActiveAppearance());
            face.setAppearance(style.getSelectedAppearance());
        }
    }

    public void setSelectionMode(SelectionMode mode) {
        selectionMode = mode;
    }

    public void setEditable(boolean b) {
        if (b == editable)
            return;

        editable = b;
        changeAppearance(editable ? style.getActiveAppearance() : style.getAppearance());
    }

    public boolean isEditableMode() {
        return editable;
    }
}
